//
// Created by xili on 2024/9/9 14:56.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    int mod = 1000000007;

    int distinctSubseqII(string s) {
        int ans = 1;
        vector<int> cnt(26, 0);
        for (auto &it: s) {
            int newadd = (ans - cnt[it - 'a'] + mod) % mod;
            cnt[it - 'a'] = (cnt[it - 'a'] + newadd) % mod;
            ans = (ans + newadd) % mod;
        }
        return (ans - 1 + mod) % mod;
    }
};